<template>
  <div id="app" :class="isMobile?'ismobile':'pcApp'">
    <router-view v-wechat-title="$route.meta.title" v-if="isRouterAlive"></router-view>
  </div>
</template>
<script>
import './assets/font/font.css';
export default {
  name: 'app',
  provide() {
    return {
      reload: this.reload
    };
  },
  data() {
    return {
      isRouterAlive: true
    };
  },
  mounted() {
    if (this.isMobile) {
      const oScript = document.createElement('script');
      oScript.type = 'text/javascript';
      oScript.src = 'https://lch.longfor.com/jsbridge3.0/lxjsSdk.js';
      document.body.appendChild(oScript);
      document.title = this.$route.meta.title;
      createIfm('setNavigationBarTitle', this.$route.meta.title);
    }
  },
  watch: {
    $route(newVal, oldVal) {
      this.reload();
      if (newVal.name == 'home' && oldVal.name != null) {
        location.reload();
      } else {
        this.$forceUpdate();
      }
    }
  },
  updated() {
    if (this.isMobile) {
      const oScript = document.createElement('script');
      oScript.type = 'text/javascript';
      oScript.src = 'https://lch.longfor.com/jsbridge3.0/lxjsSdk.js';
      document.body.appendChild(oScript);
      document.title = this.$route.meta.title;
      createIfm('setNavigationBarTitle', this.$route.meta.title);
    }
  },
  methods: {
    reload() {
      this.isRouterAlive = false;
      this.$nextTick(() => {
        this.isRouterAlive = true;
      });
    }
  },
  computed: {
    // 判断用户使用得是什么手机端；
    isMobile() {
      let flag = navigator.userAgent.match(
        /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
      );
      this.$store.commit('setisMobile', flag);
      return flag;
    }
  }
};
</script>
<style>
html,
body {
  height: auto;
}
</style>